/*
 * Copyright (C) 2003-2011 eXo Platform SAS.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see<http://www.gnu.org/licenses/>.
 */
package khiem.sonar.demo;

import org.sonar.wsclient.Sonar;
import org.sonar.wsclient.services.Measure;
import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;

/**
 * Created by The eXo Platform SAS
 * Author : eXoPlatform
 *          exo@exoplatform.com
 * Jun 22, 2011  
 */
public class SonarClient {
  
  public static void main(String[] args) {
    String host = "https://sonar.exoplatform.org";
    String resKey = "org.exoplatform.cs:exo.cs.eXoApplication.contact.webapp:trunk:org.exoplatform.contact.webui.popup.UIMembershipSelector";
      //"http://localhost:9000"; // //;
    String username = "admin";
    String password = "admin";
    
    Sonar sonar = Sonar.create(host, username, password);
      //Sonar.create(host); //
    //Resource domInspector = sonar.find(ResourceQuery.createForMetrics("org.exoplatform.cross:eXoDOMInspector", "coverage", "lines", "violations"));
    ResourceQuery query = new ResourceQuery(resKey);
    query.setIncludeTrends(true);
    query.setMetrics("coverage", "lines", "complexity", "commented_out_code_lines", "qi-complex-distrib");
    //Resource domInspector = sonar.find(ResourceQuery.createForMetrics("org.exoplatform.content.service.ContentPlugin:cs:trunk", "coverage", "lines", "violations"));
    //System.out.println(domInspector.getMeasure("coverage").getValue());
    Resource file = sonar.find(query);
    
    Measure measure = file.getMeasure("lines");
    System.out.print(measure.getValue());
  }
}
